import {LogLanguage} from "../dist/index.js"

// 真实日志测试用例
const testCases = [
  '2025-08-06 11:23:02,290 INFO [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] service.SBYBaseService (com.cn.yft.ora.bank.sby.service.SBYBaseService:179) - 【HTTP响应结果处理】resData>>>>>>>>>>>>>：null',
  '2025-08-06 11:23:02,290 ERROR [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] service.SBYBaseService (com.cn.yft.ora.bank.sby.service.SBYBaseService:181) - 【HTTP响应结果处理】返回结果为空',
  '2025-08-06 11:23:02,290 INFO [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] service.SBYBaseService (com.cn.yft.ora.bank.sby.service.SBYBaseService:70) - 【身边云接口】请求结束:ResponseMessageVO(reqId=70011754450582062, merId=1749611201012113, funCode=7001, version=V1.0, resData=null, resCode=6213, resMsg=【HTTP响应结果处理】返回结果为空, sign=null)'
]

console.log("🔍 Testing real log format parsing...")

testCases.forEach((testCase, index) => {
  console.log(`\n📝 Test case ${index + 1}:`)
  console.log(`Input: ${testCase}`)
  
  try {
    const tree = LogLanguage.parser.parse(testCase)
    console.log("✅ Parse successful!")
    
    // 检查所有节点
    let foundElements = {
      FATALExpression: [],
      ERRORExpression: [],
      INFOExpression: [],
      WARNINGExpression: [],
      DebugExpression: [],
      DATEExpression: [],
      CLASSPATHExpression: [],
      TIDExpression: [],
      StringLiteral: [],
      NumberExpression: []
    }
    
    tree.iterate({
      enter: (node) => {
        const text = testCase.slice(node.from, node.to)
        if (foundElements.hasOwnProperty(node.name)) {
          foundElements[node.name].push(text)
        }
      }
    })
    
    // 输出结果
    Object.entries(foundElements).forEach(([name, elements]) => {
      if (elements.length > 0) {
        console.log(`✅ Found ${elements.length} ${name}: ${elements.join(', ')}`)
      }
    })
    
    // 检查是否有任何元素被识别
    const totalElements = Object.values(foundElements).flat().length
    if (totalElements === 0) {
      console.log("❌ No special elements found")
    }
    
  } catch (error) {
    console.log(`❌ Parse failed: ${error.message}`)
  }
}) 